package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.BaseTeacherDao;
import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;
import com.itheima.edu.info.manager.util.StaffFactory;
import com.itheima.edu.info.manager.util.TeacherFactory;

public class TeacherService {
//    static TeacherDao teacherDao = new TeacherDao();
    BaseTeacherDao teacherDao = TeacherFactory.getTeacherDao();

    public boolean addTeacher(Teacher teacher) {
        boolean success = teacherDao.addTeacher(teacher);
        return success;
    }

    public boolean isExist(String tid) {
        Teacher[] teachers = teacherDao.findAllTeacher();
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] != null && teachers[i].getId().equals(tid)){
                return true;
            }
        }
        return false;
    }

    public Teacher[] findAllTeacher() {
        int num = 0;//纪录数组非空元素个数
        Teacher[] teachers = teacherDao.findAllTeacher();
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] != null){
                num++;
            }
        }
        if (num != 0){
            return teachers;
        }
        else {
            return null;
        }
    }

    public void deleteTeacher(String tid) {
        teacherDao.deleteTeacher(tid);
    }

    public void updateTeacher(Teacher teacher) {
        teacherDao.updateTeacher(teacher);
    }

    public boolean isFull() {
        int num = 0;
        Teacher[] teachers = teacherDao.findAllTeacher();
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] != null){
                num++;
            }
        }
        if (num >= teachers.length){
            return true;
        }else {
            return false;
        }
    }
}
